# K3dApp makefile
# author: Jan Koci	honza.koci@email.cz

# Our program name and path
PROGRAMS = stdmap

# C++ compiler
CC = g++

CD = cd -P

OK = -e "\e[1;32mOK \e[0m"

#Object directory
OBJDIR = debug

#Output directory
OUTDIR = ../../bin



CONFIGS = debug release

ifeq (,$(findstring $(CONFIG),$(CONFIGS)))
    CONFIG = debug
endif

ifeq (,$(findstring debug,$(CONFIG)))
    CFLAGS = -O2 -DNDEBUG
	OBJDIR = release
else
    CFLAGS = -g -D_DEBUG
	OBJDIR = debug
endif



# Warning flags for C programs
WARNCFLAGS = -Wall -Wshadow -Wpointer-arith \
	-Wcast-qual -Wcast-align \
	-Woverloaded-virtual # -W

# Warning for linker
WARNLD = -Wbad-function-cast -Wstrict-prototypes -Wmissing-declarations 


# All the .cpp files
SOURCES = $(wildcard *.cpp)
# And the corresponding .o files
OBJECTS = $(SOURCES:%.cpp=$(OBJDIR)/%.o)

# The first target in the makefile is the default target. It's usually called
# "all".
all: $(PROGRAMS)

#Get current directory
CUR_DIR = "./"

# We assume we have one program (`ourprogram') to build, from all the object
# files derived from .cpp files in the current directory.
$(PROGRAMS): $(OBJECTS)
	$(CD) $(OUTDIR)
	$(CC) $(WARNCFLAGS) $(WARNLD) $(CFLAGS) -fPIC -o $(PROGRAMS) $(OBJECTS)

# Include known dependecies from -MMD
-include $(OBJECTS:.o=.d)

# How to make *.o files
$(OBJDIR)/%.o: %.cpp
	@echo "Create application directory" $(OUTDIR)
	@mkdir -p $(OUTDIR)
	@echo $(OK)
	@echo "Create object directory" $(OUTDIR)
	@mkdir -p $(OBJDIR)
	@echo $(OK)
	@echo "Object compiling" $(OBJECTS)
	$(CC) -MMD $(WARNCFLAGS) -c $(CFLAGS) $< -o $@
	@echo $(OK)

# "clean" removes files not needed after a build.
clean:
#remove files
	rm -f $(OBJECTS) $(OBJDIR)/*.d *~ tags gmon.out 
#remove directory
	rmdir $(OBJDIR)	
